let auditResult;
$(function () {

    let checkId = sessionStorage.getItem('checkId');
    $('input[type="radio"]').each(function (k, v) {
        $(v).click(function () {
            $(".refuseReason").hide();
            if ($(v).val() == 1) {
                $(".refuseReason").show()
            }
        })
    })

    $('body').on('click', '.upImg', function () {
        let str = `<div class="popup"></div><div class='magnify'><img src='${$(this).attr('src')}'></div>`;
        $('body').append(str)
    })

    $('body').on('click', '.popup', function () {
        $(this).remove();
        $(".magnify").remove();
    })

    AjaxGet('/userAunt/getUserAuntById', {id: checkId}).then(function (response) {
        let userInfo = response.data.userDO;  //用户
        let matron = response.data.jazUserAuntDO;  // 月嫂

        auditResult = matron.auditResult;
        if (matron.auditResult == 1) {
            $(".refuseReason").show();
            $(".refuseReason textarea").val(matron.refuseReason);
        }

        $("#username").html(userInfo.name); //用户名字
        $("#mobile").html(userInfo.orderPhone); //用户电话
        $("#nativePlace").html(userInfo.nativePlace); // 籍贯
        $("#age").html(userInfo.age +'岁'); // 年龄
        $("#sex").html(userInfo.sex == '1' ? '男' : '女'); // 性别
        $("#zodiac").html(userInfo.zodiac); // 生肖
        $("#constellation").html(userInfo.constellation); // 星座
        $("#maritalStatus").html(userInfo.maritalStatus); // 婚姻
        $("#education").html(userInfo.education); // 学历
        $("#height").html(userInfo.height +'cm'); // 身高
        $("#weight").html(userInfo.weight + 'kg'); // 体重
        // $("#detailedAddress").html(userInfo?.detailedAddress); // 现住址
        $("#detailedAddress").html(userInfo?.province == userInfo?.city ? `${userInfo?.city}${userInfo?.district}${userInfo?.detailedAddress}` :
            `${userInfo?.province}${userInfo?.city}${userInfo?.district}${userInfo?.detailedAddress}`); // 现住址

        $("#gmtCreate").html(matron.auditResult == 1 ? '未通过' : '待审核'); // 签约状态
        $("#time").html(matron.createTime); // 时间
        $("#introduction").html(matron.introduction); // 自我介绍
        $("#residentHome").html(matron.residentHome == '0' ? '是' : '否'); // 是否住家
        $("#desireSalary").html( '￥'+ matron.desireSalary +'/月'  || '' ); // 期望工资
        $("#workExperience").html(matron.workExperience + '年'); // 工作经验
        // $("#skill").html(matron.skill); // 个人技能
        // $("#experience").html(matron.experience); // 工作经历

        $("#serveTotal").html(matron.serveTotal);
        $("#examinationCondition").html(matron.examinationCondition.replace(',','、'));
        $("#nurseContent").html(matron.nurseContent.replace(',','、'));
        $("#skill").html(matron.skill.replace(',','、'));

        if(matron.experience) {
            let experience = JSON.parse(matron.experience),srr = '';
            // $("#experience").html( matron.experience || '' ); // 工作经历
            experience.map(function (v){
                srr += `
                         <div class="layui-form-item">
                            ${v.startTime}~${v.endTime}
                        </div>
                        <div class="layui-form-item">
                            ${v.describe}
                        </div>`;
            })
            $("#experience").html(srr);
        }


        $("#order").html(matron.orderCount); // 订单数

        $("#recharge").html( response.data.jazSysProject );

        //个人标签
        let str = '';
        response.data.jazSysLabelDO?.forEach(function (v) {
            str += `<span class="layui-badge layui-bg-green" style="margin-right: 10px">${v.describe}</span>`
        })
        $("#tips").html(str);

        //寸照
        $("#inchPhoto").html(`<img class="upImg" width="100" src="${matron.inchPhoto}">`);
        //身份证正面
        $("#idPhotoFront").html(`<img class="upImg" width="100" src="${matron.idPhotoFront}">`);
        //身份证反面
        $("#idPhotoSide").html(`<img class="upImg" width="100" src="${matron.idPhotoSide}">`);

        //工作/生活照
        str = '';
        let lifePhoto = matron.lifePhoto.split(',')
        lifePhoto?.forEach(function (v) {
            str += `<div class="layui-inline">
                            <img class="upImg" width="100" src="${v}">
                        </div>
                       `;
        });
        $("#lifePhoto").html(str);
        //技能证书
        str = '';
        let certificate = matron.certificate.split(',')
        certificate?.forEach(function (v) {
            str += `<div class="layui-inline">
                            <img class="upImg" width="100" src="${v}">
                        </div>
                       `;
        });
        $("#certificate").html(str);
        //体检报告
        str = '';
        let report = matron.report.split(',')
        report?.forEach(function (v) {
            str += `<div class="layui-inline">
                            <img class="upImg" width="100" src="${v}">
                        </div>
                       `;
        });
        $("#report").html(str);
        //展示状态
        $('input[name="showStatus"]').each(function (k, v) {
            if ($(v).val() == matron.auditResult) {
                $(v).attr('checked', true)
            }
        })
    }).catch(function (error) {
        layer.msg(error.msg)
    })



})

$("#but").click(function () {
    let matronId = sessionStorage.getItem('checkId');
    let show = $('input[type="radio"]:checked').val();

    if (!show) {
        layer.msg('请选择审核状态');
        return false;
    }

    AjaxPost('/userAunt/examineAunt', {
        id: matronId,
        auditStatus: 1,
        auditResult: show,
        showStatus: show,
        refuseReason: $(".refuseReason textarea").val()
    }).then(function (response) {
        parent.layer.msg("操作成功");
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
        parent.load();
    }).catch(error => {
        layer.msg(error.msg)
    })
})

